package com.axx.android.psuh;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.axx.android.letter.activity.LetterDetailActivity;
import com.igexin.sdk.GTIntentService;
import com.igexin.sdk.PushManager;
import com.igexin.sdk.message.GTCmdMessage;
import com.igexin.sdk.message.GTTransmitMessage;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2017/8/8 0008.
 */

public class PushService extends GTIntentService {
    @Override
    public void onReceiveServicePid(Context context, int i) {

    }

    @Override
    public void onReceiveClientId(Context context, String s) {
    }

    @Override
    public void onReceiveMessageData(Context context, GTTransmitMessage gtTransmitMessage) {
        parseContent(context,new String(gtTransmitMessage.getPayload()));
    }

    private void parseContent(Context context, String content) {
        try {
            JSONObject jsonObject = new JSONObject(content);
            String type = jsonObject.getString("type");
            if ("00".equals(type)){
                String letterId = (String) jsonObject.get("letterId");
                Intent intent = new Intent(context, LetterDetailActivity.class);
                intent.putExtra("from","detail");
                intent.putExtra("id",letterId);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void onReceiveOnlineState(Context context, boolean b) {

    }

    @Override
    public void onReceiveCommandResult(Context context, GTCmdMessage gtCmdMessage) {
    }
}
